package org.example.http;

import java.io.IOException;

public class HttpServletImpl implements HttpServlet {
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String method = request.getMethod();
        if (method.equals("GET")) {
            doGet(request, response);
        } else if (method.equals("POST")) {
            doPost(request, response);
        } else if (method.equals("OPTIONS")) {
            doOptions(request, response);
        } else if (method.equals("PUT")) {
            doPut(request, response);
        } else if (method.equals("HEAD")) {
            doHead(request, response);
        } else if (method.equals("TRACE")) {
            doTrace(request, response);
        }
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405 错误 doGet 访问不支持");
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405 错误 doPost 访问不支持");
    }

    @Override
    public void doOptions(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405 错误 doOptions 访问不支持");
    }

    @Override
    public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405 错误 doPut 访问不支持");
    }

    @Override
    public void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405 错误 doHead 访问不支持");
    }

    @Override
    public void doTrace(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405 错误 doTrace 访问不支持");
    }

    @Override
    public void init() {

    }

    @Override
    public void destroy() {

    }
}
